import 'package:cbec_app/components/base/base_image.dart';
import 'package:cbec_app/components/base/base_interactive.dart';
import 'package:cbec_app/components/common/common_style.dart';
import 'package:cbec_app/components/common/star_rating.dart';
import 'package:cbec_app/routes/routes.dart';
import 'package:cbec_app/utils/Tools.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

/// 商品列表
class OrderGoodsItem extends StatelessWidget {
  ///商品id
  final String? channelID;

  ///订单id
  final String? orderID;

  ///主单号
  final String? paySn;

  ///次单号
  final String? sn;

  ///商品主图
  final String? goodsImg;

  ///商品标题
  final String? title;

  ///标签
  final List? tags;

  ///标签类型
  final int? tagType;

  //价格
  final double? price;

  ///商品数量
  final int? num;

  ///单位
  final String? unit;

  ///商品总价
  final double? totalAmount;

  ///评分
  final int? star;

  ///退款金额
  final double? refundAmount;

  ///退款数量
  final int? refundNum;

  ///是否评价
  final int? isComment;

  ///评论内容
  final String? comment;

  ///订单状态 0-已取消 10-待支付 20-待发货 30-已发货 40-已签收 50-已完成
  final int? status;

  /// 退款状态
  final int? returnStatus;

  final bool? isShowSpec;

  final String? spuSpecBody;

  final bool? isShowPingJia;

  final bool? isShowPingJiaKuang;

  const OrderGoodsItem({
    super.key,
    this.goodsImg = '',
    this.title = '',
    this.tags,
    this.price = 0,
    this.num = 0,
    this.totalAmount = 0,
    this.star = 0,
    this.refundAmount = 0,
    this.refundNum = 1,
    this.isComment = 0,
    this.status = 0,
    this.channelID = '',
    this.orderID = '',
    this.paySn = '',
    this.sn = '',
    this.comment = '',
    this.unit = '件',
    this.tagType = 0,
    this.returnStatus,
    this.isShowSpec,
    this.spuSpecBody,
    this.isShowPingJia = false,
    this.isShowPingJiaKuang = false,
  });

  @override
  Widget build(BuildContext context) {
    String tag = tagType == 0
        ? '一般贸易'
        : tagType == 1
            ? '保税'
            : '海外直邮';

    return Column(
      children: [
        Container(
          margin: EdgeInsets.only(bottom: 10.w),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              //左边图片
              BaseImage(
                url: goodsImg!,
                width: 100.w,
                height: 100,
                borderRadius: BorderRadius.circular(10.w),
              ),
              //右边
              Container(
                margin: EdgeInsets.only(left: 10.w),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  //三列
                  children: [
                    Row(
                      children: [
                        Container(
                          color: Tools.fromHex("#FFEEEE"),
                          padding: EdgeInsets.fromLTRB(5.w, 2.w, 5.w, 2.w),
                          margin: EdgeInsets.only(right: 5.w),
                          child: Text(
                            tag,
                            style: const TextStyle(fontSize: 10, fontWeight: FontWeight.w300, color: Colors.red),
                          ),
                        ),
                      ],
                    ),
                    //商品标题和价格数量
                    Container(
                      // width: 220.w,
                      margin: EdgeInsets.only(top: 10.w, bottom: 12.w),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          SizedBox(
                            width: 160.w,
                            child: Text(
                              title!,
                              softWrap: true,
                              maxLines: 2,
                              overflow: TextOverflow.ellipsis,
                              style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w300),
                            ),
                          ),
                          Column(
                            children: [
                              Text(
                                "￥$price",
                                style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w300),
                              ),
                              Text(
                                "共$num件",
                                style: TextStyle(fontSize: 11, fontWeight: FontWeight.w500, color: Tools.fromHex("#999999")),
                              ),
                              status == 40
                                  ? isComment == 0
                                      ? BaseInteractive(
                                          onClick: () {
                                            Get.toNamed(Routes.comment, arguments: {'channelID': channelID, 'orderID': orderID, 'paySn': paySn, 'sn': sn});
                                          },
                                          childWidget: Padding(
                                            padding: const EdgeInsets.all(8.0),
                                            child: Container(
                                              padding: EdgeInsets.fromLTRB(4.w, 1.w, 4.w, 2.w),
                                              decoration: border_radis(Colors.white, borderColor: Colors.red),
                                              margin: EdgeInsets.only(top: 5.w),
                                              child: const Text("去评价",
                                                  style: TextStyle(
                                                    fontSize: 10,
                                                    fontWeight: FontWeight.w500,
                                                    color: Colors.red,
                                                  )),
                                            ),
                                          ),
                                        )
                                      : const SizedBox()
                                  : const SizedBox(),
                            ],
                          )
                        ],
                      ),
                    ),

                    isShowSpec == true
                        ? SizedBox(
                            width: ScreenUtil().screenWidth - 100.w - 40,
                            child: RichText(
                              maxLines: 2, // 限制最大行数
                              overflow: TextOverflow.ellipsis, // 超出部分显示省略号
                              text: TextSpan(
                                text: spuSpecBody ?? '', // 显示的文本内容
                                style: const TextStyle(
                                  color: Colors.black, // 设置默认文本颜色
                                  fontSize: 14.0, // 设置默认文本大小
                                ),
                              ),
                              softWrap: true, // 支持换行
                            ),
                          )
                        : const SizedBox(),

                    //评星
                    star != 0 && star != null
                        ? LStarRating(
                            size: 20,
                            selectedColor: Tools.fromHex("#F93B19"),
                            rating: star!.toDouble(),
                            leftTextWidget: Text("商品评分", style: setTextStyle(12, FontWeight.w500, Tools.fromHex("#333333"))),
                            isShowLeftText: true,
                          )
                        : const SizedBox(),
                    refundAmount != 0
                        ? Container(
                            transform: Matrix4.translationValues(0, -5.h, 0),
                            width: 220.w,
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Text("申请数量$refundNum", style: setTextStyle(12, FontWeight.w300, Tools.fromHex("#F83F2D"))),
                                returnStatus == 20
                                    ? Text(
                                        "已退款￥$refundAmount",
                                        style: setTextStyle(
                                          12,
                                          FontWeight.w300,
                                          Tools.fromHex("#F83F2D"),
                                        ),
                                      )
                                    : const SizedBox(),
                              ],
                            ),
                          )
                        : const SizedBox()
                  ],
                ),
              ),
            ],
          ),
        ),
        isShowPingJia == true
            ? Container(
                margin: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: [
                    BaseInteractive(
                      onClick: () {
                        Get.toNamed(Routes.comment, arguments: {'channelID': channelID, 'orderID': orderID, 'paySn': paySn, 'sn': sn});
                      },
                      childWidget: Container(
                        padding: EdgeInsets.fromLTRB(10.w, 2.w, 10.w, 2.w),
                        decoration: border_radis(Colors.white, borderColor: Colors.red, radiusValue: 15),
                        margin: EdgeInsets.only(top: 5.w),
                        child: const Text("评价",
                            style: TextStyle(
                              fontSize: 14,
                              fontWeight: FontWeight.w500,
                              color: Colors.red,
                            )),
                      ),
                    ),
                  ],
                ),
              )
            : const SizedBox(),
        if (isShowPingJiaKuang == true) ...[
          comment != '' && comment != null
              ? Container(
                  alignment: Alignment.centerLeft,
                  margin: EdgeInsets.only(bottom: 10.w),
                  padding: EdgeInsets.all(10.w),
                  decoration: border_radis(Tools.fromHex("#F3F5F7")),
                  child: Text(comment ?? '您没有填写评价内容', style: setTextStyle(12, FontWeight.w300, Tools.fromHex("#666666"))),
                )
              : Container(
                  alignment: Alignment.centerLeft,
                  margin: EdgeInsets.only(bottom: 10.w),
                  padding: EdgeInsets.all(10.w),
                  decoration: border_radis(Tools.fromHex("#F3F5F7")),
                  child: Text('您没有填写评价内容', style: setTextStyle(12, FontWeight.w300, Tools.fromHex("#666666"))),
                ),
        ] else ...[
          const SizedBox(),
        ],
      ],
    );
  }
}
